﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DiagnosisToolBL;
using com.diagnosis.tool.bl;

namespace webappui
{
    public partial class DTMainForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            String newVal = textBoxSymptomVal.Text;

            if (null == newVal || newVal.Trim().Length == 0)
            {
                return;
            }

            listBoxSymptoms.Items.Add(newVal);
            
            DoProcess();

            textBoxSymptomVal.Text = "";
        }

        protected void btnRemove_Click(object sender, EventArgs e)
        {
            ListItem selectedItem = listBoxSymptoms.SelectedItem;
            
            if(null != selectedItem)
            {
                listBoxSymptoms.Items.Remove(selectedItem);
                DoProcess();
            }
        }

        private void DoProcess()
        {
            listBoxFoundDiseases.Items.Clear();

            List<String> symptomsToCheck = new List<String>();

            foreach (ListItem item in listBoxSymptoms.Items)
            {
                symptomsToCheck.Add(item.Text);
            }

            ExtendedDiseaseForDisplay[] foundDiseases = GetDiseasesFactory.GetInterface(null).GetDiseases(symptomsToCheck.ToArray());

            foreach (var curFoundDisease in foundDiseases)
            {
                listBoxFoundDiseases.Items.Add(curFoundDisease.ToString());
            }
        }

        /*[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            // Create array of movies  
            string[] movies = { "Star Wars", "Star Trek", "Superman", "Memento", "Shrek", "Shrek II" };

            // Return matching movies  
            return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
        }*/

        [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            return GetDiseasesFactory.GetInterface(null).GetSymptoms(prefixText, count);
        }

        protected void btnAddPlus_Click(object sender, EventArgs e)
        {
            textBoxSymptomVal.Text = "*" + textBoxSymptomVal.Text;

            btnAdd_Click(sender, e);
        }  
    }
}